package com.penton.util.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.EditText;

/**
 * 这是一个自定义的EditView被画很多行再每两行的中间
 */
public class LinedEditText extends EditText {
	
    /*
     * 一个是矩形  一个是装绘  主要显示画图的样式
     */
    private Rect mRect;
    private Paint mPaint;

    /*
     * 构造函数
     */
    public LinedEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
      
        mRect = new Rect();
        mPaint = new Paint();
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setColor(0x8FF00FF);
    }
    
    /**
     * 这个是具体的画法
     */
    @Override
    protected void onDraw(Canvas canvas) {
        int count = getLineCount();
        Rect r = mRect;
        Paint paint = mPaint;

        for (int i = 0; i < count; i++) {
            int baseline = getLineBounds(i, r);

            canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint);
        }

        super.onDraw(canvas);
    }
}
